package com.lixiang.userinfo.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 全局的过滤器（解决跨域问题）
 * @author 李湘
 * @date 2018-10-21
 */
@Controller
public class AccessHeaderInterceptor extends HandlerInterceptorAdapter{
	
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		//设置返回内容格式
		response.setContentType("application/json;charset=UTF-8");
        /*request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");*/
		//===================================================
		//设置js请求josn跨域
		response.setHeader("Access-Control-Allow-Origin","*");
		response.setHeader("Access-Control-Allow-Methods","POST,GET,PUT,DELETE");//POST,GET,PUT,DELETE
		response.setHeader("Access-Control-Allow-Headers","Access-Control,jwt,content-type");
		response.setHeader("Allow","POST");
		response.setCharacterEncoding("UTF-8");
		return true;
	}
	
	

}
